 
 /*
  * Author  : Pallab
  * Program : 448.cxx
  * 
  * 2011-11-24 21:31:42
  * I have not failed, I have just found 10000 ways that won't work.
  *
  */
 #include <iostream>
 #include <algorithm>
 #include <vector>
 #include <sstream>
 #include <fstream>
 #include <string>
 #include <list>
 #include <map>
 #include <set>
 #include <queue>
 #include <stack>
 #include <functional>
 #include <bitset>
 #include <iomanip>
 
 #include <ctime>
 #include <cassert>
 #include <cstdio>
 #include <cmath>
 #include <cstring>
 #include <climits>
 #include <cstring>
 #include <cstdlib>
 
 using namespace std;
 
 #define VI vector< int >
 #define CI( x ) scanf("%d",&x)
 #define CL( x ) scanf("%lld",&x)
 #define CD( x ) scanf("%lf",&x )
 #define foR(i,st,ed) for(int i = st ; i < ed ; ++i )
 #define fo(i,ed) foR( i , 0 , ed )
 #define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
 #define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
 #define bip system("pause")
 #define Int long long
 #define pb push_back
 #define SZ(X) (int)(X).size()
 #define LN(X) (int)(X).length()
 #define mk make_pair
 #define f first
 #define s second
 #define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
 
 inline void wait(double seconds) {
	 double endtime = clock()+(seconds * CLOCKS_PER_SEC);
	 while (clock() < endtime) {
		 ;
	 }
 }
 string line;
 vector<string> w;
 int tot;
 
 inline void split(){
	 w.clear();
	 stringstream ss(line);
	 for(string tmp=""; getline(ss,tmp,','); ){
		 int l = LN(tmp);
		 if( l < 1 )continue;
		 for( int i=0;i<l;++i ){
			 if( tmp[i]=='"' ){
				 ++i;
				 string d="";
				 while( i<l && tmp[i]!='"' ){
					 d+=tmp[i];
					 ++i;
				 }
				 w.pb(d);
			 }
		 }
	 }
 }
 

 const int maxn = 16;
 int G[maxn+1][maxn+1];
 inline void build(){
	 SET(G,-1);
	 for(int i=0;i<tot;++i){
		 for(int j=i+1;j<tot;++j){
			#define COLOR(X) ( (X) =='S' || (X) == 'C' ? 1 : 0 ) 
			#define RANK(X,Y) ( (X) == (Y) ? 1 : 0 ) 
			if( RANK( w[i][0],w[j][0] ) || ( COLOR(w[i][1]) == COLOR(w[j][1]) ) ) {
				G[i][j] = G[j][i] = 1;
			}
		 }
	 }
 }
#define MOD 1234567891

int bit[maxn+1];
Int dp[ 1<< (maxn+1) ] [ maxn+1 ];
int done;
inline void bitcount(){
	for(int i=0 ;i<=maxn;++i){
		bit[i] = ( 1<<i );		
	}
}

 Int go(int msk, int pre){
	 if( msk == done ){
		 return 1;
	 }
	 
	 if( dp[msk][pre]>=0) {
		 return dp[msk][pre];
	 }
	 Int ways=0;
	 for(int i=0;i<tot;++i){
		if( (msk&bit[i])==0 && G[pre][i]==1 ){
			Int v = go( msk|bit[i] , i );
			ways = ( ways + v )%MOD;
		}
	 }
	return dp[msk][pre]=ways;
 }
 inline void Proc(){
	 split();
	 tot = SZ(w);
	 done = (1<<tot)-1;
	 build();
	 Int cc=0;
	 
	 SET(dp,-1);
	 for(int i=0;i<tot;++i){
		 cc = ( cc%MOD ) + ( go( bit[i], i ) %MOD );
		 cc%=MOD;
		 
	 }
	 cout<<cc<<"\n";
 }
 int main() {
	 bitcount();
	 while( getline(cin,line) ){
		 Proc();
	 }
	 
	 return 0;
 }